package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.UserDao;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.Set;

@Service(interfaceClass = UserService.class)
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;
    @Autowired
    private RoleService roleService;
    @Autowired
    private PermissionService permissionService;

    @Override
    public User findUserByUsername(String username) {
        User user=userDao.findUserByUsername(username);
        //通过用户查角色
        Set<Role>roleSet= roleService.findRoleByUserId(user.getId());
        user.setRoles(roleSet);
        for (Role role : roleSet) {
        //通过角色查权限`t_permission`
        Set<Permission>permissionSet=permissionService.findPermissionByUserId(role.getId());
        role.setPermissions(permissionSet);
        }
        return user;
    }
}
